package cn.yuanqiao.web.controller.archive.liyong;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import cn.yuanqiao.archive.liyong.domain.YqdyDa;
import cn.yuanqiao.archive.liyong.service.IYqdyDaService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.web.page.TableDataInfo;

/**
 * 我的订阅Controller
 * 
 * @author sy
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/archive/yqdy_da")
public class YqdyDaController extends BaseController
{
    @Autowired
    private IYqdyDaService yqdyDaService;

    /**
     * 查询我的订阅列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:list')")
    @GetMapping("/list")
    public TableDataInfo list(YqdyDa yqdyDa)
    {
        startPage();
        List<YqdyDa> list = yqdyDaService.selectYqdyDaList(yqdyDa);
        return getDataTable(list);
    }

    /**
     * 导出我的订阅列表
     */
    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:export')")
    @Log(title = "我的订阅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqdyDa yqdyDa)
    {
        List<YqdyDa> list = yqdyDaService.selectYqdyDaList(yqdyDa);
        ExcelUtil<YqdyDa> util = new ExcelUtil<YqdyDa>(YqdyDa.class);
        util.exportExcel(response, list, "我的订阅数据");
    }

    /**
     * 获取我的订阅详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:query')")
    @GetMapping(value = "/{dyId}")
    public AjaxResult getInfo(@PathVariable("dyId") Long dyId)
    {
        return success(yqdyDaService.selectYqdyDaByDyId(dyId));
    }

    /**
     * 新增我的订阅
     */
    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:add')")
    @Log(title = "我的订阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqdyDa yqdyDa)
    {
        return toAjax(yqdyDaService.insertYqdyDa(yqdyDa));
    }

    /**
     * 修改我的订阅
     */
    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:edit')")
    @Log(title = "我的订阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqdyDa yqdyDa)
    {
        return toAjax(yqdyDaService.updateYqdyDa(yqdyDa));
    }

    /**
     * 删除我的订阅
     */
    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:remove')")
    @Log(title = "我的订阅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dyIds}")
    public AjaxResult remove(@PathVariable Long[] dyIds)
    {
        return toAjax(yqdyDaService.deleteYqdyDaByDyIds(dyIds));
    }

    /**
     * 根据关键词查询档案并添加到订阅与档案中间表，用于定时任务
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:remove')")
    @Log(title = "我的订阅", businessType = BusinessType.INSERT)
    @GetMapping("/search")
    public AjaxResult search(@RequestParam("tenantCode") String tenantCode)
    {
        yqdyDaService.search(tenantCode);
        return AjaxResult.success();
    }

    /**
     * 修改消息状态
     */
//    @PreAuthorize("@ss.hasPermi('archive:yqdy_da:updateState')")
    @Log(title = "我的订阅", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/updateState")
    public void getInfo(@RequestBody YqdyDa yqdyDa)
    {
        yqdyDaService.updateYqdyDaState(yqdyDa);
    }
}
